package com.algoshow.view;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import static com.algoshow.utils.SystemConstants.SYSTEM_HEIGHT;
import static com.algoshow.utils.SystemConstants.SYSTEM_WIDTH;


/**
 * @author vvv
 * @date 2023-05-14 22 57
 * discription
 */

public class FirstMenu {
    private JPanel jp;
    private JButton lianbiao,shunxubiao,erchashu,tu,guangyibiao,chuan,zhan;
    private Color defaultColor = Color.BLACK;
    private Color hoverColor = Color.WHITE;
    private JLabel label;


    public FirstMenu() {
        // 创建主窗口
        JFrame frame = new JFrame("算法展示");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(SYSTEM_WIDTH, SYSTEM_HEIGHT);
        frame.setLocationRelativeTo(null); // 设置窗口位置为屏幕中心
        // 创建背景容器
        JPanel backgroundPanel = new JPanel() {
            // 重写paintComponent方法以绘制背景图片
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                // 在这里设置图片
                Image backgroundImage = new ImageIcon("src/resources/background.jpg").getImage();
                g.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), this);
            }
        };
        backgroundPanel.setLayout(null);  // 使用绝对布局以便手动设置按钮位置

        // 创建按钮
        JButton lianbiao = new JButton("链表");
        JButton shunxubiao = new JButton("顺序表");
        JButton paixu = new JButton("排序");
        JButton erchashu = new JButton("二叉树");
        JButton tu = new JButton("图");
        JButton chuan = new JButton("栈与队列");
        lianbiao.setBounds(300, 266, 350, 100);
        lianbiao.setContentAreaFilled(false);      //按钮透明
        lianbiao.setBorderPainted(false);  //无边框
        lianbiao.setFont(new Font("宋体", Font.ROMAN_BASELINE, 60));
        lianbiao.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        lianbiao.setForeground(defaultColor);
        //给按钮绑定点击事件
        lianbiao.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.dispose();
                //点击特定的按钮就跳到特定的2级菜单的方法，
                new SecondMenu().showTest5();
            }
        });
        // 设置鼠标动作事件监听器
        lianbiao.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                lianbiao.setForeground(hoverColor);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                lianbiao.setForeground(defaultColor);
            }
        });
        backgroundPanel.add(lianbiao);
        /*************/
        shunxubiao.setBounds(300, 420, 350, 100);
        shunxubiao.setContentAreaFilled(false);      //按钮透明
        shunxubiao.setBorderPainted(false);  //无边框
        shunxubiao.setFont(new Font("宋体", Font.ROMAN_BASELINE, 60));
        shunxubiao.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        shunxubiao.setForeground(defaultColor);
        //给按钮绑定点击事件
        shunxubiao.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.dispose();
                //点击特定的按钮就跳到特定的2级菜单的方法，
                new SecondMenu().showTest4();
            }
        });
        // 设置鼠标动作事件监听器
        shunxubiao.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                shunxubiao.setForeground(hoverColor);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                shunxubiao.setForeground(defaultColor);
            }
        });
        backgroundPanel.add(shunxubiao);
        /************/


        erchashu.setBounds(300, 580, 350, 100);
        erchashu.setContentAreaFilled(false);      //按钮透明
        erchashu.setBorderPainted(false);  //无边框
        erchashu.setFont(new Font("宋体", Font.ROMAN_BASELINE, 60));
        erchashu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        erchashu.setForeground(defaultColor);
        //给按钮绑定点击事件
        erchashu.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.dispose();
                //点击特定的按钮就跳到特定的2级菜单的方法，
                new SecondMenu().showTest3();
            }
        });
        // 设置鼠标动作事件监听器
        erchashu.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                erchashu.setForeground(hoverColor);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                erchashu.setForeground(defaultColor);
            }
        });
        backgroundPanel.add(erchashu);
        /***********/

        tu.setBounds(1000, 266, 350, 100);
        tu.setContentAreaFilled(false);      //按钮透明
        tu.setBorderPainted(false);  //无边框
        tu.setFont(new Font("宋体", Font.ROMAN_BASELINE, 60));
        tu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        tu.setForeground(defaultColor);
        //给按钮绑定点击事件
        tu.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.dispose();
                //点击特定的按钮就跳到特定的2级菜单的方法，
                new SecondMenu().showTest7();
            }
        });
        // 设置鼠标动作事件监听器
        tu.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                tu.setForeground(hoverColor);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                tu.setForeground(defaultColor);
            }
        });
        backgroundPanel.add(tu);
        /************/


        paixu.setBounds(1000, 420, 350, 100);
        paixu.setContentAreaFilled(false);      //按钮透明
        paixu.setBorderPainted(false);  //无边框
        paixu.setFont(new Font("宋体", Font.ROMAN_BASELINE, 60));
        paixu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        paixu.setForeground(defaultColor);
        //给按钮绑定点击事件
        paixu.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.dispose();
                //点击特定的按钮就跳到特定的2级菜单的方法，
                new SecondMenu().showTest2();
            }
        });
        // 设置鼠标动作事件监听器
        paixu.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                paixu.setForeground(hoverColor);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                paixu.setForeground(defaultColor);
            }
        });
        backgroundPanel.add(paixu);
        /***********/


        chuan.setBounds(1000, 588, 350, 100);
        chuan.setContentAreaFilled(false);      //按钮透明
        chuan.setBorderPainted(false);  //无边框
        chuan.setFont(new Font("宋体", Font.ROMAN_BASELINE, 60));
        chuan.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        chuan.setForeground(defaultColor);
        //给按钮绑定点击事件
        chuan.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
               frame.dispose();
                //点击特定的按钮就跳到特定的2级菜单的方法，
                new SecondMenu().showTest6();
            }
        });
        // 设置鼠标动作事件监听器
        chuan.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                chuan.setForeground(hoverColor);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                chuan.setForeground(defaultColor);
            }
        });
        backgroundPanel.add(chuan);
        // 将背景容器添加到主窗口
        frame.getContentPane().add(backgroundPanel);

        frame.setVisible(true);
    }
}
